package com.lyp.mvpsupermanage.user.view.activity.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.blankj.utilcode.util.ToastUtils;
import com.lyp.mvpsupermanage.R;
import com.lyp.mvpsupermanage.network.bean.LoginBean;
import com.lyp.mvpsupermanage.user.presenter.LoginPresenter;
import com.lyp.mvpsupermanage.user.presenter.LoginView;
import com.lyp.mvpsupermanage.user.presenter.MvpActivity;


import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends MvpActivity<LoginPresenter> implements LoginView {

    @Bind(R.id.et_loginuserName)
    EditText mUserName;
    @Bind(R.id.et_loginuserpwd)
    EditText mUserPwd;

    String userName;
    String userPwd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);


    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter(this);
    }


    @Override
    public void getLoginSuccess(LoginBean model) {
        toastShow("登录成功！");
    }

    @Override
    public void getLoginFail(String msg) {
        toastShow("网络不给力！");
    }

    //------------onclick--------------//
    @OnClick(R.id.btn_logins)
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_logins:
//                if (isNull()) {
//                    mvpPresenter.Login(userName, userPwd);
////                    getLogins();
////                    login();
//                  }
                break;
          }
    }



    //判断用户名和密码是否为空
    private void login() {
        String userName = mUserName.getText().toString();
        String userPwd = mUserPwd.getText().toString();
        //判断用户名是否为空
        if (userName.isEmpty()) {
            ToastUtils.showShort("请输入用户名");
            return;
        }
        if (userPwd.isEmpty()){ //判断密码是否为空
            ToastUtils.showShort("请输入密码");
            return;
        }
//        PrefsUtils.getInstance().putBoolean(Constants.IS_LOGINED_FLAG, true);
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}
